import { Injectable, HttpException, HttpStatus } from '@nestjs/common';

@Injectable()
export class WorkService {
  getUserById(id: string) {
    // 当 id 为 "0" 时，抛出 HttpException
    if (id === '0') {
      throw new HttpException('用户不存在', HttpStatus.NOT_FOUND);
    }

    // 当 id 为非数字时，抛出普通 Error
    if (isNaN(Number(id))) {
      throw new Error('无效的用户 ID');
    }

    // 正常情况返回用户信息
    return {
      id: parseInt(id),
      name: `用户${id}`,
      email: `user${id}@example.com`
    };
  }
}